﻿using System;
using System.Linq;
using Castle.MonoRail.Framework.Helpers;
using StateTheaterDataModel;

namespace StateTheater.Models
{
    public class ProductionDetails
    {
        public string Title { get; set; }
        public int  ID { get; set; }
        public string Troupe { get; set; }
        public string TroupeTag { get; set; }
        public int TroupeID { get; set; }
        public string Venue { get; set; }
        public string VenueTag { get; set; }
        public int VenueID { get; set; }
        public string ToString(string siteRoot)
        {
            return String.Format(@"<h2><a href=""{0}/Show/{1}/Display.rails"">{2}</a>" +
                             @" by <a href=""{0}/Troupe/name/{3}.rails"">{4}</a></h2>" +
                             @"<h3> at <a href=""{0}/Venue/{5}.rails"">{6}</a></h3>",
                                siteRoot, ID, Title, 
                                TroupeTag, Troupe,
                                VenueID, Venue);
        }
        public static ProductionDetails GetDetails(StateTheaterDataContext db, int id)
        {
            return (from prod in db.Productions
                    where prod.ProductionID == id
                    select new ProductionDetails
                    {
                        Title = prod.Play.Title,
                        ID = prod.ProductionID,
                        Troupe = prod.Troupe.Name,
                        TroupeID = prod.TroupeID,
                        TroupeTag = prod.Troupe.shortname,
                        Venue = prod.Venue.Name,
                        VenueTag = prod.Venue.Shortname,
                        VenueID = prod.VenueID.Value
                    }).Single();
        }
    }
}
